<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'', styles:'bootstrap,font-awesome,animate,style,bootstrap-table,layui-date,auto-complete,dtvalidate,layui,chosen'}){%>
    <style type="text/css">
        body{padding-top:10px;
            padding-left: 10px;}
        *{margin:0;padding:0;list-style-type:none;}
        a,img{border:0;}
        .demo h2{font-size:16px;color:#3366cc;height:30px;}
        .demo li{float:left;}
    </style>
    <%}%>
</head>

<body>
<div class="row">
    <div class="col-sm-12">
        <!-- START 右侧数据 -->
        <div class="ibox float-e-margins" style="margin-bottom: 0px;">
            <div class="ibox-content" style="padding:15px 20px 0px 20px;">
                <form id="search-form" role="form" class="form-horizontal" autocomplete="off">
                    <div class="form-group">
                        <label class="control-label col-sm-1">属性:</label>
                        <div class="col-sm-2">
                            <select   name="produceType" class="form-control" >
                                <option value="">请选择</option>
                                <option value="产前">产前</option>
                                <option value="产中">产中</option>
                            </select>
                        </div>
                        <label class="control-label col-sm-1">属性名称:</label>
                        <div class="col-sm-2">
                            <input type="text"  name="produceName" class="form-control"  />
                        </div>
                        <a class="search-btn btn btn-success" style="margin-bottom: 0px;">查询</a>
                    </div>
                </form>
            </div>
        </div>
        <!-- START 右侧数据 -->
        <div class="ibox float-e-margins" style="margin-bottom: 0px;">
            <div id="toolbar" class="btn-group" style="margin-bottom:5px;">
                <button  class="add-btn layui-btn  layui-btn-sm"  style="margin-top: -6px;margin-left: -4px">
                    <i class="fa fa-check" aria-hidden="true"></i> 新增质检属性
                </button>
            </div>
            <!-- START 操作按钮 -->
            <!-- END 操作按钮 -->

            <!-- START 数据表格 -->
            <table id="relatedTable"
                   data-toolbar="#toolbar"
                   data-side-pagination="server"
                   data-pagination="true"
                   data-resizable="true"
                   data-url="/sea/supply/quality/produce/type/findByCnd.do"
                   data-page-size="15"
                   class="table table-striped table-hover"
            >
            </table>
            <!-- END 数据表格 -->
        </div>
    </div>
</div>


<div id="layer_supplier_window" style="display: none;overflow-x: hidden;overflow-y: hidden">
    <!-- START 内容部分 -->
    <div class="container" >
        <form class="form-horizontal" id="info-supplier-form" method="post" autocomplete="off" style="margin: auto">
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-2" style="max-width: 100px">属性</label>
                <div class="col-sm-8" style="max-width: 300px;">
                    <select  id="produceType" name="produceType" class="form-control" >
                        <option value="">请选择</option>
                        <option value="产前">产前</option>
                        <option value="产中">产中</option>
                        <option value="产后">产后</option>
                    </select>
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-2" style="max-width: 100px">属性名称</label>
                <div class="col-sm-8" style="max-width: 300px;">
                    <input type="text" id="produceName" name="produceName" class="form-control"  />
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-7" style="max-width: 100px"></label>
                <button type="button" class="save-produce-btn btn btn-primary">
                    <i class="fa fa-save"></i> 保存
                </button>
            </div>
        </form>
    </div>
    <!-- END 内容部分 -->
</div>
<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,dtvalidate,dtvalidate-lang-zh_cn,bootstrap-table-zh-CN,laydate,layer,chosen,chosen-demo'}){}%>
<script>
    var $relatedTable = $('#relatedTable');
    $(function(){
        //START 表格配置
        $relatedTable.bootstrapTable({
            columns: [
                {
                    title: '属性',
                    field: 'produceType',
                    align: 'center',
                    valign: 'middle'
                },{
                    title: '属性名称',
                    field: 'produceName',
                    align: 'center',
                    valign: 'middle'
                },{
                    title: '创建时间',
                    field: 'createTime',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '操作',
                    field: 'operate',
                    align: 'center',
                    valign: 'middle',
                    formatter: optFormatter
                }
            ],
            onLoadSuccess : function(){

                //删除数据字典详情信息
                $('.del-btn').on('click',function(){
                    var delid = $(this).attr('data-val'),delname = $(this).attr('data-val-name');
                    //删除提示
                    layer.confirm('确定要删除当前数据？<br>['+delname+']', {
                        btn: ['确定','取消'],title:'提示'
                    }, function(){
                        $.post('/sea/supply/quality/produce/type/delete.do',{id: delid},function(data){
                            if( data.ok ){
                                layer.msg(data.msg,{icon: 1,time: 1500},function(){
                                    //刷新页面
                                    $relatedTable.bootstrapTable('refresh');
                                });
                            }else{
                                layer.msg(data.msg,{icon: 0,time: 1500});
                            }
                        });
                    });
                });
            },onExpandRow: function (index, row, $detail) {
                InitSubTable(index, row, $detail);
            }
        });
    });

    // 条件查询
    $('.search-btn').on('click',function () {
        $relatedTable.bootstrapTable('refresh', { url:'${ctxPath}/sea/supply/quality/produce/type/findByCnd.do?'+$('#search-form').serialize() });
    });

    // 操作菜单
    function optFormatter(value,row){
        var content = '';
        content += '&nbsp;<a class="del-btn btn btn-xs btn-danger" data-val-name="'+row.produceName+'" data-val="'+row.id+'" title="删除"><i class="fa fa-trash-o"></i> 删除 </a>';
        return content;
    }

    $('.add-btn').on('click',function () {
            layer.open({
                type:1,
                title:'新增质检属性',
                area:['550px','370px'],
                skin:'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
                shadeClose:false,
                resize: false,
                scrollbar: false,
                maxmin: false,//出现最大化按钮
                content:$('#layer_supplier_window')
            })
    });


    $(".save-produce-btn").on('click',function () {
        var produceType = $("#produceType").val();
        if (produceType == '') {
            parent.layer.msg('请选择质检属性！', {icon: 0, time: 1500, shade: [0.8, '#393D49']});
            return;
        }
        var produceName = $("#produceName").val();
        if (produceName == '') {
            parent.layer.msg('请填写质检名称！', {icon: 0, time: 1500, shade: [0.8, '#393D49']});
            return;
        }
        $.ajax({
            url: "/sea/supply/quality/produce/type/save",
            data: {
                produceType: produceType,
                produceName: produceName
            },
            type: "post",
            success: function (data) {
                if (data.ok) {
                    layer.msg("新增成功！", {
                        icon: 0, btn: ['确定'], time: 0, shade: [0.8, '#393D49'], yes: function (index, layero) { // 默认的是 按钮一
                            layer.closeAll();
                            $relatedTable.bootstrapTable('refresh');
                        }
                    });
                } else {
                    layer.msg(data.msg, {
                        icon: 0, btn: ['确定'], time: 0, shade: [0.8, '#393D49'], yes: function (index, layero) { // 默认的是 按钮一
                            layer.closeAll();
                        }
                    });
                }
            },
        });
    })
</script>
</body>
</html>
